/**
	@file	Token.h
	@date	2010/09/08
	@author sang-soo kim
	@brief  간략한 word token을 저장하는 class
*/
#if !defined(__WORD_H__)
#define __WORD_H__
#pragma once
#include <stdint.h>
#include <string>
#include "Token.h"
class Word
: public Token
{
public:
    uint16_t pos;
    uint16_t begin;
    uint16_t end;
public:
	Word() : pos(0), begin(0), end(0)
    {};
	virtual ~Word() {};
 
    /** 
    * constructor
    */
    void clear()
    {
        m_pLinePtr = NULL;
        length =0;
        pos = 0;
        end=0;
        begin = 0;
        type = 0;
    }
    /**
    *   operator =
    */
    virtual Word operator = ( const Word obj) 
    {
        m_pLinePtr  = obj.m_pLinePtr;
        length      = obj.length;
        pos         = obj.pos;
        begin       = obj.begin;
        end       = obj.end;
        type       = obj.type;
        return * this;
    }
    void setPos( uint8_t p )
    {
        pos = p;
    }
    uint8_t getPos()
    {
        return ( uint8_t) pos;
    }
    /**
    *   utf-8을 utf16/32 code로 return;
    *   @return: uint32_t unicode
    */
    uint32_t getUnicode()
    {
        uint32_t unicode= 0x0;
        int i;
        uint8_t chars[10];

        for( i=0;i< length; i++)
        {
            chars[ i ] = (uint8_t) ( * (m_pLinePtr+i)  );
        }
        chars[ i ] = 0x0;

        switch( length )
        {
            case 1:
                return ( uint32_t) chars[ 0 ];
                break;
            case 2:
                chars[0] =  chars[0] & 0x1f;
                chars[1] =  chars[1] & 0x3f;

                unicode =  (uint32_t)( chars[0] >> 2 );
                unicode = unicode << 8 | ( ( chars[0] << 6 ) | chars[1] );
                return unicode;

            case 3:
                chars[0] =  chars[0] & 0x0f;
                chars[1] =  chars[1] & 0x3f;
                chars[2] =  chars[2] & 0x3f;
                unicode = ( chars[0] << 4 ) | (chars[1] >> 2);
                unicode = unicode << 8 | ( (chars[1] << 6 ) |  chars[2]   ) ;
                return (  uint32_t )unicode;
            case 4:
                return (  uint32_t ) 0x00;

            default:
                return ( uint32_t) 0x00;

        }

        return ( uint32_t) 0x00;
    }
};

#endif


